为了账号安全,请及时绑定邮箱和手机立即绑定

Spring Boot —— spring-boot-starter-parent

标签:
SpringBoot

你的项目pom.xml文件中,应该存在如下代码:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version></parent>

你是否知道这是干啥的?

这是Spring Boot的父级依赖,这样当前的项目就是Spring Boot项目了。
spring-boot-starter-parent 是一个特殊的starter,它用来提供相关的Maven默认依赖。使用它之后,常用的包依赖可以省去version标签。

当我们搭建web应用的时候,可以像下面这样添加spring-boot-starter-web依赖:

<dependencies>
   <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
   </dependency></dependencies>

简单的演示下 Spring Boot 项目:

maven文件看起来是这个样子的:

<?xml version="1.0" encoding="UTF-8"?>
  <project xmlns="http://maven.apache.org/POM/4.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>springBootLearn</groupId>
    <artifactId>springBootLearn</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
    </parent>

   <dependencies>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
       </dependency>
   </dependencies></project>

HelloworldController.java

@RestControllerpublic class HelloworldController {    @RequestMapping("/")    public String say(){        return "Hello Spring Boot";
    }
}

Application.java

@SpringBootApplicationpublic class Application {    public static void main(String[] args) {
        SpringApplication.run(Ch1Application.class, args);
    }
}

运行main方法,启动项目,然后在浏览器访问http://localhost:8080,就能看到 "Hello Spring Boot"。



作者:打铁大师
链接:https://www.jianshu.com/p/54cdfe4e0cac


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消